﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;
using DAL;
using System.Reflection;

namespace 包覆门
{
    public partial class DotonWlView : Form
    {
        public DotonWlView()
        {
            InitializeComponent();
        }
        public string Danhao { get; set; }
        private OrderDAL dal = new OrderDAL();
       private  DataTable detail = new DataTable();
       private int i = 1;
        //加载
        private void DotonWlView_Load(object sender, EventArgs e)
        {
            //foreach (RenderingExtension re in reportViewer1.LocalReport.ListRenderingExtensions())
            //{
            //    //屏蔽掉你需要取消的导出功能 Excel PDF WORD  
            //    if (re.Name == "Excel")//屏蔽掉Excel PDF WORD类似
            //    {
            //        FieldInfo fi = re.GetType().GetField("m_isVisible", BindingFlags.Instance | BindingFlags.NonPublic);
            //        fi.SetValue(re, false);
            //    }ReportDetailOrderByDanhao
            //}


            DataTable detailIntial = dal.ReportWLDetailOrderByDanhao(Danhao);
            DataTable wlorder = new DataTable();
            DataTable mainorder = dal.ReportMainOrderByDanhao(Danhao);
            
            //组织订单详情
            detail = detailIntial.Clone();
           
            foreach(DataRow dr in detailIntial.Rows){
                
                if (dr["zslb"].ToString().Equals("0"))
                {
                    if (!dr["iszh"].ToString().Equals("0"))
                    {
                        AddDataRowToTable(dr, true);
                        i=i+2;
                    }
                    else {
                        AddDataRowToTable(dr, false);
                        i=i+1;
                    }
                }
                else 
                {
                    AddDataRowToTable(dr, false);
                    i=i+1;
                }
            }
            //组织物料订单
            wlorder = dal.ReportWlsl(Danhao);

            //内置参数赋值 
            ReportParameter[] rps = new ReportParameter[6];
            if (mainorder.Rows.Count == 1) {
                DataRow dr = mainorder.Rows[0];
                rps[0] = new ReportParameter("username", dr["username"].ToString());
                rps[1] = new ReportParameter("danhao", dr["danhao"].ToString());
                rps[2] = new ReportParameter("sname", dr["dealername"].ToString());
                rps[3] = new ReportParameter("planorder", dr["planorder"].ToString());
                rps[4] = new ReportParameter("xbrq", DateTime.Now.AddDays(7).ToString("yyyy-MM-dd"));
                rps[5] = new ReportParameter("jhrq", DateTime.Now.AddDays(17).ToString("yyyy-MM-dd"));
            }

            reportViewer1.LocalReport.ReportPath = Application.StartupPath + "\\DotonWlReport1.rdlc";
            
            //指定数据集,数据集名称后为表,不是DataSet类型的数据集
            this.reportViewer1.LocalReport.DataSources.Clear();
            this.reportViewer1.LocalReport.SetParameters(rps);
            //this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", dt));
            this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DataSet2", detail));
            this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", wlorder));
            //显示报表
            this.reportViewer1.RefreshReport();

        }
        public void AddDataRowToTable(DataRow dr,bool flag) {

            if (flag)
            {
                string top = dr["xbTopheight"].ToString();
                string down = dr["xbDownheight"].ToString();
                string topName = dr["xbmc"] + "(上芯板)";
                string downName = dr["xbmc"] + "(下芯板)";
                DataRow drNew = detail.NewRow();
                drNew=dr;
                drNew["xbheight"] = top;
                drNew["xbmc"] = topName;
                drNew["xh"] = i;
                detail.ImportRow(drNew);
                DataRow drNew1 = detail.NewRow();
                //drNew1=dr;
                drNew1["xh"] = (i+1);
                drNew1["xbheight"] = down;
                drNew1["xbwidth"] = dr["xbwidth"];
                drNew1["xbmc"] = downName;
                detail.Rows.Add(drNew1);
            }
            else {
                dr["xh"] = i;
                detail.ImportRow(dr);
            }
        }
    }
}
